aa = [1,2,3]3-element Vector{Int64}:
1
2
3
Some quick tips that we’ve learnt the hard way…
View>Toggle Word Wrap or alt-Za = b, any change in b will automatically cause the same change in a. For example, let’s make an array of three numbers:aa = [1,2,3]3-element Vector{Int64}:
1
2
3
Here we make a copy of aa and call it bb.
bb = aa
print(bb)[1, 2, 3]
Now, we replace the second element of bb with the value 41.
bb[2] = 41
bb3-element Vector{Int64}:
1
41
3
The default behaviour of = in Julia is to UPDATE any copy of the array, so we see the same change in aa:
aa3-element Vector{Int64}:
1
41
3
Whoa… that’s not what we expect, though it’s pretty cool. This approach is advantageous because it lets Julia save memory, however, it is not ideal.
To remedy this, and create copies that don’t update their parent or other offspring, we can force c to be an independent copy of a using the deepcopy function:
cc = deepcopy(aa)3-element Vector{Int64}:
1
41
3
cc[3] = 101
aa,cc([1, 41, 3], [1, 41, 101])
You can view a .csv or .txt file by clicking on a file name in the project directory (left panel) - this opens a viewing window. CSV’s also have a built in ‘Preview’ mode - try using right click>Open Preview on a .csv file and check it out.
Docstrings are a supplement to #-based comments for documenting your workflow. Basically, any string that appears just before an object will be interpreted as documenting it. When you use a docstring it is possible to call that description using help (? in the REPL) or hovering over the object in VSCode. This can be very useful when you start declaring variables or building your own functions.
"a wonderfully documented and described variable"
var = 101var
you can (should) also do this with functions
"""
_rategradient(∂X, ∂Y)
Returns the rate of change in units of the values stored in the grid, and the
angle of the change in wind direction, *i.e.* an angle of 180 means that the
value is increasing *from* the south. When both ∂X and ∂Y are equal to 0, the
angle is assumed to be 0.
"""
function _rategradient(∂X::T, ∂Y::T) where {T <: Number}
if ∂X == ∂Y == 0.0
return (0.0, 0.0)
end
m = sqrt(∂X^2 + ∂Y^2)
Δ = ∂X >= 0.0 ? 0.0 : 180.0
θ = rad2deg(atan(∂X, ∂Y)) + Δ
θ = ∂X > 0.0 ? θ + 180.0 : θ
return (m, θ)
end_rategradient